package com.station.server.entity;

import com.station.client.proxies.PFuelTank;
import com.station.client.proxies.PStation;

import javax.persistence.*;
import java.util.List;

/**
 * User: JinJavaMojo
 * Date: 25.09.13
 */
@Table(name = "STATION", schema = "public", catalog = "")
@Entity
public class Station extends PlaceableEntity {

    @OneToMany(targetEntity = FuelTank.class, cascade = CascadeType.ALL, mappedBy = "stationId")
    private List<FuelTank> tanks;

    @OneToMany(targetEntity = PetrolPump.class, cascade = CascadeType.ALL)
    private List<PetrolPump> pumps;

    public List<FuelTank> getTanks() {
        return tanks;
    }

    public void setTanks(List<FuelTank> tanks) {
        this.tanks = tanks;
    }

    public static Station tranform(PStation pStation) {
        Station entity = (Station) BaseEntity.getInstance(pStation, Station.class);
        entity.size = Size.transform(pStation.pSize);
        entity.coordinates = Coordinates.transform(pStation.pCoordinates);
        entity.persist();
        if (pStation.getTanks() != null)
            for (PFuelTank pFuelTank : pStation.getTanks())
                FuelTank.transform(pFuelTank);
        return entity;

    }
}
